<?php

class Blog_Model_DbTable_Comentarios extends Zend_Db_Table_Abstract
{

    protected $_name = 'blog_comentarios';

    //obtener creador
    //$this->findParentRow('Application_Model_DbTable_Usuarios', 'Creador')->nombre_real
    //obtener articulo
    //$this->findParentRow('Blog_Model_DbTable_Articulos', 'Articulo')->id
    protected $_referenceMap    = array(
        'Articulo' => array(
            'columns'           => 'articulo',
            'refTableClass'     => 'Blog_Model_DbTable_Articulos',
            'refColumns'        => 'id'
        ),
        'Creador' => array(
            'columns'           => 'creador',
            'refTableClass'     => 'Application_Model_DbTable_Usuarios',
            'refColumns'        => 'id'
        )
    );
    
    public function obtenerComentario($id){
        $select = $this->select();
        $select->where('id = ?', $id);
        return $this->fetchRow($select);  
    }

    public function borrarComentario($id){
        $this->delete(array('id = ?' => $id));
    }
    
    public function crearComentario($texto,$id_art,$id_cliente){
        $data = array(
            "texto" => $texto, 
            "articulo" => $id_art, 
            "creador" => $id_cliente
        );
        $this->insert($data);
    }

}
